package com.hanamaki.unit.testng.work;

import com.hanamaki.unit.junit.util.FileUtil;
import com.hanamaki.unit.junit.util.JDBCUtil;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class CircleTest {

    static Circle circle;

    @BeforeMethod
    public void setUp() {
        circle = new Circle();
    }


    @Test(dataProvider = "dp1")
    public void isCircle(double radius, boolean result,double perimeter) {

        boolean isCircle = CircleTest.circle.isCircle(radius);
        System.out.println(isCircle);
        Assert.assertEquals(isCircle, result);
        if (isCircle) {
            double perimeter1 = circle.perimeter();
            System.out.println(perimeter1);
            System.out.println(perimeter);
            Assert.assertEquals(perimeter1,perimeter);
        }

    }
    @DataProvider
    public Object[][] dp1() {
        return new Object[][]{
                new Object[]{0, true, 3},
                new Object[]{1, false, 2 * Math.PI},
                new Object[]{3.4, true, 2 * Math.PI * 3.4}
        };
    }

    @Test(dataProvider = "dp3")
    public void isCircle1(String radius, String result, String perimeter, String area) {
        boolean isCircle = CircleTest.circle.isCircle(Double.parseDouble(radius));
        System.out.println(isCircle);

        Assert.assertEquals(isCircle, Boolean.parseBoolean(result));
        if (isCircle) {
            double perimeter1 = circle.perimeter();
            System.out.println(perimeter1);
            System.out.println(perimeter);
            Assert.assertEquals(perimeter1, Double.parseDouble(perimeter));

            double area1 = circle.area();
            System.out.println(area1);
            System.out.println(Double.parseDouble(area));
            Assert.assertEquals(area1,Double.parseDouble(area));
        }

    }

    @DataProvider
    public Object[][] dp2() {
        return FileUtil.getFileContent("src/com/hanamaki/unit/testng/work/CircleTest.txt");
    }

    @DataProvider
    public Object[][] dp3() {
        return JDBCUtil.getSqlContent("circle");
    }

}
